﻿<UserControl x:Class="Hisaab.Client.Modules.Core.Transaction.View.Transactions"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:conv="clr-namespace:Hisaab.Client.Modules.Core.Converters"
             xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:Helpers="clr-namespace:Hisaab.Client.Common.Helpers;assembly=Hisaab.Client.Common" xmlns:View="clr-namespace:Hisaab.Client.Modules.Core.Transaction.View" Helpers:RibbonTabVisibilityBehaviour.ContextualGroup="{Binding ElementName=cmTransaction, Mode=OneWay}"
             Helpers:RibbonTabVisibilityBehaviour.Focus="True"
             Helpers:RibbonTabVisibilityBehaviour.ViewModel="{Binding .}"
             Helpers:RibbonTabVisibilityBehaviour.IsVisible="{Binding IsActive, Converter={StaticResource VisibilityConverter}}"
             mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <DataTemplate x:Key="TagListViewTemplate">
                        <Border BorderBrush="#DADADA" BorderThickness="1,1,1,1" CornerRadius="2,2,2,2" Margin="1 0 1 0">
                            <TextBlock Text="{Binding Name}" Padding="5 0 5 0" Style="{DynamicResource ListText}" Background="{DynamicResource GrayGradient}" />
                        </Border>
                    </DataTemplate>
                    <ItemsPanelTemplate x:Key="HorizontalItemPanelTemplate">
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ResourceDictionary>
                <ResourceDictionary>
                    <conv:AccountIdToNameConverter x:Key="AccountNameConverter" />
                    <conv:TagIdToNameConverter x:Key="TagConverter" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="6" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300*" />
            <ColumnDefinition Width="6" />
            <ColumnDefinition Width="300*" />
        </Grid.ColumnDefinitions>
        <ListBox Grid.Column="0" Grid.RowSpan="3" ItemsSource="{Binding Transactions}" SelectedItem="{Binding SelectedTransaction, Mode=TwoWay}"
                  SelectionMode="Single" HorizontalContentAlignment="Stretch" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="2" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="5"/>
                        </Grid.ColumnDefinitions>
                        <Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Style="{DynamicResource TransactionImage}" Height="16" Width="16" />
                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=Title}" Style="{DynamicResource ListMainHeading}" />
                        <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding Path=Amount, StringFormat='{}{0:C}'}" Style="{DynamicResource ListSubHeading}"  HorizontalAlignment="Right"/>
                        <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=Account, Converter={StaticResource AccountNameConverter}}" Style="{DynamicResource ListSubHeading}" />
                        <TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding Path=Date, StringFormat={}{0:dddd MMMM dd\, yyyy}}" Style="{DynamicResource ListSubHeading}"/>
                        <ItemsControl Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding Path=Tags}"
                                      ItemTemplate="{StaticResource TagListViewTemplate}" ItemsPanel="{StaticResource HorizontalItemPanelTemplate}" />
                        <Border Grid.Row="3" Grid.ColumnSpan="4" Style="{DynamicResource DottedBorder}" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <GridSplitter Grid.Column="1" Grid.RowSpan="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        <GridSplitter Grid.Column="2" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        <ContentControl Grid.Column="2" Content="{Binding SelectedTransaction}" >
            <ContentControl.ContentTemplate>
                <DataTemplate>
                    <View:TransactionView />
                </DataTemplate>
            </ContentControl.ContentTemplate>
        </ContentControl>
        <Grid Grid.Column="2" Grid.Row="2" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="6" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <chartingToolkit:Chart Grid.Column="0" Title="Tags Total" >
                <chartingToolkit:Chart.LegendStyle>
                    <Style TargetType="datavis:Legend">
                        <Setter Property="Width" Value="0" />
                    </Style>
                </chartingToolkit:Chart.LegendStyle>
                <chartingToolkit:ColumnSeries ItemsSource="{Binding ExpanseChartData}"
                    IndependentValueBinding="{Binding Path=Key, Converter={StaticResource TagConverter}}"
                    DependentValueBinding="{Binding Path=Value}" />
            </chartingToolkit:Chart>
            <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
            <chartingToolkit:Chart Grid.Column="2" Title="Expanse Comparison" >
                <chartingToolkit:PieSeries ItemsSource="{Binding ComparisonChartData}"
                    IndependentValueBinding="{Binding Path=Key}"
                    DependentValueBinding="{Binding Path=Value}"  />
            </chartingToolkit:Chart>
        </Grid>
    </Grid>
</UserControl>